<?php
/**************************************************************************************************
|
| AudioShare - Audio Sharing Script
| http://www.audiosharescript.com
| webmaster@audiosharescript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.audiosharescript.com/eula.html and to be bound by it.
|
| Copyright (c) 2010 AudioShareScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$query = "select * from audios";
$executequery=$conn->execute($query);
$audios = $executequery->getrows();

//mkdir($config[basedir] . "adata/123456");
/*rmdir($config['basedir'] . "adata/2011");
rmdir($config['basedir'] . "adata/2012");
rmdir($config['basedir'] . "adata/2013");
rmdir($config['basedir'] . "adata/2010");
echo "deleted dir";
exit;*/
if(!empty($audios)){
    foreach($audios as$key=>$val){
        $ext=$val["extension"];
        $AUDIOID=$val["AUDIOID"];
        $audioyear=date("Y",strtotime($val["date_added"]));
        $catName=fetch_category_name_from_id($val["categories"]);
        echo $catName."--".$config['basedir'] . "/adata/".$catName."<br />";
        if(!is_dir($config['basedir'] . "/adata/".$catName))
             mkdir($config['basedir'] . "/adata/".$catName);
        
        if(!is_dir($config[basedir] . "/adata/".$catName."/".$audioyear)){
             //echo ($config[basedir] . "adata/".$catName."/".$audioyear)."---<br />";
               mkdir($config['basedir'] . "/adata/".$catName."/".$audioyear);
        }
        
        $original = $config['basedir']."/adata/".$catName."/".$audioyear. "/" . $AUDIOID . $ext;
        $uploaded = $config['basedir']."/adata/". $AUDIOID .  $ext;
        copy($uploaded, $original);
        //copy($original, $uploaded);
        unlink($uploaded);
        
    }
}
echo "moved";
exit;
?>